试图在java中实现以下内容:
在线搜索(或自己制作)递归算法,用于转换一个十进制 any Base (2-16).
这是我的密码:
import java.util.*;
public class Converter
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int b, n;
System.out.println("Number: ");
n = sc.nextInt()
我只是写了一个程序来找到游戏的领导者。规则:在完成所有一轮比赛后,找到领队.Every回合,给两队分,并找出领先差距。最后,找出哪支球队获得的巨大领先优势,那支球队将是赢家。下面类型的我写的程序,但我得到的数字格式异常时,从用户收到的输入。
Exception in thread "main" java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(Integer.java:542)
at java.lang.Integer.parseInt(Integer.java:615
我目前正在做一个类的作业,我想知道如何在字符串输入中找到一个整数。到目前为止,在代码中我已经创建了一种退出循环的方法。请不要给我代码,只是给我一些想法。请记住,我对java还是个新手,所以请耐心等待。谢谢。编辑:我忘了提到字符串输入应该类似于"woah123“,它应该只找到"123”部分。抱歉的
import java.util.Scanner;
public class DoubleTheInt
{
public static void main(String[] args)
{
int EXIT = 0;
while(EXI
我想分析一下图像中的像素值。我尝试在十六进制像素值的位置2和4提取值,并将其显示在控制台上。我在代码中使用子字符串。我试着运行这个程序,但是过了一段时间,它显示了错误字符串。
显示错误:
java.lang.StringIndexOutOfBoundsException: String index out of range: 4
at java.lang.String.substring(String.java:1907)
at getPixelData.getPixelData(getPixelData.java:51)
at getPixelRGB.main(getPixelRGB.jav
在我的代码中,我使用"\n“作为分隔符,因为用户的输入字符串中可能有一些'sapce‘。但是出现了一个例外,我是confused.So的新手,我非常感谢您的帮助。
我的代码是:
import java.util.Scanner;
public class ScannerDemo {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
scanner.useDelimiter("\n");
Sy
我也许有个简单的问题,但我完全被困住了。
我有剧本
SELECT COALESCE(COUNT(id), 0) as MyFiels from table
它工作得很好,当我有零值时,它会显示0。
但是我想要的不是0,我可以看到一行=“无结果”,例如。
我试过:
SELECT COALESCE(to_char(COUNT(id), 'NO RESULT')) as MyFiels from table
PostgreSQL显示错误消息:
ERROR: "E" is not supported
SQL state: 0A000
我哪里不对?有什么想法吗?
我在我的模型中有一个如上定义的属性,在某些情况下包含一个Int。
var value: Any?
我知道,如果我先转换为String,然后转换为Int,我可以做到这一点
value.toString().toInt() // works
有没有一种方法可以跳过之前的字符串转换呢?当我尝试将直接强制转换为Int时,得到以下错误
FATAL EXCEPTION: main
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
我试图把一张图片从一个活动发送到另一个,我读类似的问题,但没有解决我的问题。我用来发送这张照片的代码是
public void aceptar (View view) {
ImageView iv = (ImageView) findViewById(R.id.foto);
iv.setImageBitmap(BitmapFactory.decodeFile(foto));
File file = new File(foto);
Intent intent = new Inte
我需要把这些值作为字符串。我该怎么做?在第一组方向上,我得到了七个整数。因此,我将所有变量设置为除参与者外的整数,但我也希望将所有值作为字符串。
import java.util.Scanner;
public class Baseball {
public static void main(String[] args) {
//opens a new scanner instance
Scanner baseball = new Scanner(System.in);
// Allows a person to enter players name
我被下面的Java代码搞糊涂了,在下面的代码中,我尝试使用两个方法将一个对象转换为int:
Object o = 1;
System.out.println((int) o);
Class <?> t = int.class;
System.out.println(t.cast(o));
传统上,第二行代码将Object转换为int,并成功执行。然而,我期望它在功能上等价的第四个抛出
Exception in thread "main" java.lang.ClassCastException: Cannot cast java.lang.Integer to in
我有一个在JFrame上输出图形的Java类。
public class ShowGraph{
public static void main(String[] args){
JFrame f = new JFrame("Example");
DrawGraph dgraph = new DrawGraph();
f.getContentPane().add(dgraph);
f.setsize(800,600);
f.setVisible(true);
f.setDefau
我知道这不是找到一个palindrome...but的最简单的方法,我希望有人能告诉我,如果有一种方法可以将多个整数字符串转换成一个int。也许这会从其他人那里建立一个单一的字符串?下面我有一个输出,它与您输入的数字相反。然而,它以一串独立的整数形式出现。我能把这个输入到一个int中,然后以某种方式将它与原始数字对应起来吗?如果我忽略了一个类似的话题,我很抱歉。我四处看看,却找不到一个能明显解决我问题的办法。
import java.util.Scanner;
public class Palindrone{
public static void main(String[] args)
import java.util.*;
public class test
{
public static void main(String[] args)
{
int i = 123;
String s = Integer.toString(i);
int Test = Integer.parseInt(s, s.charAt(0)); // ERROR!
}
}
我希望根据char位置解析输入字符串,以获得位置整数。
错误消息:
Exception in thread "main" jav
我正在尝试用Java编写一个程序,它将接受IP地址并将其转换为二进制。
这是我到目前为止所知道的:
import java.util.Scanner;
public class IpConverter{
public static void main (String[]args)
{
int result;
String data_in;
int data_out;
Scanner scan = new Scanner(System.in);
try
{
System.out.prin
我正在研究数据结构,我必须自己做一个双链接列表,创建Node和list对象,而不是使用LikedList实现,而且每当我尝试在列表中添加2个元素时,我都会遇到堆栈溢出错误,我不知道为什么。你能帮帮我吗?
public class DoubleLinked {
Node head;
Node tail;
int size;
public DoubleLinked() {
head = tail = null;
size = 0;
}
public void insertOnHead(int x) {
我正在尝试用反斜杠替换字符串的一部分。 我可以使用.replace()方法做到这一点,但是尝试使用.replaceAll()或.replaceFirst()执行同样的操作会导致错误。 下面是我正在使用的代码,我已经将它推送到一个replit class Main {
public static void main(String[] args) {
String a = "hello world";
a = a.replaceFirst("h", "H");
System.out.println(a);
Sys
我试图创建一个循环,从数组列表中获取密码,对它们进行散列,然后将散列密码传递回Person对象。
import java.util.ArrayList;
public class CompanyDatabase {
public ArrayList<Person> getPeople() {
ArrayList<Person> people = new ArrayList<Person>();
String[] u = {"Joe","Stan","Leo","John"
我真的被困在这个问题上了--我试图创建一个if语句,并在文本框中显示赋值给变量的值。我不断遇到"Cannot implicity convert int to string“构建错误。谢谢。
int n1;
int userInput = int.Parse(textBox1.Text);
if (userInput == 4)
{
n1 = 60;
}
else if (userInput ==3)
{
n1=40
我有一个类为我的应用程序声明常量
public class GroupConstants {
..
public static final int INTEGER_VALUE = 1;
public static final int LONG_VALUE = 2;
public static final int STRING_VALUE = 3;
..
}
在代码中有一组switch语句
private static Object getValue(String stringValue, Parameter parameter) throws Inval
我是C++的新手。我通常用C#编程,所以我在处理数组和循环时遇到了问题。当我尝试使用循环打印动态数组的内容时,它显示已损坏的请求区域...例如,我会让它识别数组内容使用的条件,但不打印它的内容:
// Array.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
void main()
{
int size=3;
int *p;
int myarra