This question already has answers here:
What does a "Cannot find symbol" or "Cannot resolve symbol" error mean?
(18 answers)
Closed 4 years ago.
I am new to java and facing a problem while converting a string into an integer.
my coding goes here-
import java.util.Scanner;
class Binary{
public static void main(String args[]){
Scanner takeInput = new Scanner(System.in);
System.out.println("Please Give Your Input ====> ");
String binaryInput = takeInput.nextLine();
System.out.println("Your Input Is ====> "+binaryInput);
int lenGTH=binaryInput.length();
for(int i = lenGTH ; i >= 0 ; i--){
char pOsition = binaryInput.charAt(i);
int convertIntoInteger = Int.parseInt(pOsition);
int convertIntoDouble = Double.parseDouble(convertIntoInteger);
int getPower = 0;
getPower *= Math.pow(convertIntoDouble , 2);
System.out.println("Power of " + i + " index " + getPower);
}
}
}
I am giving the screenshot for error in command prompt:enter image description here
There is no such class Int in java.
Try this:
int convertIntoInteger=Integer.parseInt(String.valueOf(p0sition));
Integer class is used to parse data in int.
Related
This question already has answers here:
What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it?
(26 answers)
Closed 5 months ago.
import java.util.Scanner;
class array2 {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
int arr_count = input.nextInt(), i;
System.out.print("Jumlah Data : ");
arr_count = input.nextInt();
int score [][] = new int[arr_count][10];
String subject [][] = new String[arr_count][1];
float total, avrg;
for (i=0;i<arr_count;i++) {
System.out.print("Mata Kuliah : ");
subject [i][0] = input.next();
System.out.print("Nilai Teori : "); score [i][0] = input.nextInt();
System.out.print("Nilai Praktik : "); score [i][1] = input.nextInt();
System.out.println();
}
System.out.println();
System.out.println("----------------------------------------------------");
System.out.println("Mata Kuliah Teori Praktikum Rata-rata");
System.out.println("----------------------------------------------------");
total = score [i][0] + score [i][1];
avrg = total/2;
System.out.print("\t"+subject+"\t"+score [i][0]+"\t"+score [i][1]+"\t"+avrg);
}
}
error = java.lang.ArrayIndexOutOfBoundsException: Index 2 out of bounds for length 2 at array2.main
How do I fix this?
total = score [i][0] + score [i][1];
This line expect to get "i" but loop already closed.
To fix - close for loop after printing this line:
System.out.print("\t"+subject+"\t"+score [i][0]+"\t"+score [i][1]+"\t"+avrg);
This question already has answers here:
What's the simplest way to print a Java array?
(37 answers)
Closed 1 year ago.
I am trying to run the following code in order to input an array of any size I desire:
import java.util.Scanner;
import java.util.Arrays;
public class testing2 {
public static void main(String[] args) {
double[] inputs = new double[5];
int currentSize = 0;
System.out.println("Please enter values, Q to quit:");
Scanner in = new Scanner(System.in);
while (in.hasNextDouble())
{
if (currentSize >= inputs.length)
{
inputs = Arrays.copyOf(inputs, 2 * inputs.length);
}
inputs[currentSize] = in.nextDouble();
currentSize++;
}
inputs = Arrays.copyOf(inputs, currentSize);
System.out.print(inputs);
}
}
But when I input any array, my output is just a combination of symbols such as: [D#13fee20c, and this is not the output I am hoping for. Could anyone help me?
You're not printing correctly:
for (int i = 0; i < input.length; i++)
System.out.print(input[i] + " ");
}
This question already has answers here:
What does a "Cannot find symbol" or "Cannot resolve symbol" error mean?
(18 answers)
Closed 4 years ago.
I am creating a version of jeopardy in Java and I just inputted the answer methods to their respective question methods and I get the "cannot find symbol" error in regards to my parameters. Can anyone help?
public static void questions400opt1 ()
{
Random rndm = new Random();
int randomQGenerator = 1 + rndm.nextInt(5);
if(randomQGenerator == 1)
{
System.out.println("");
System.out.println("QUESTION: chris pratt voices this character in the lego movie");
answer400opt1q1(total, total2, total3);
}
else if(randomQGenerator == 2)
{
System.out.println("");
System.out.println("QUESTION: anna and elsa are the main characters of this blockbuster film");
answer400opt1q2(total, total2, total3);
}
The actual answer400opt1q1 method looks like (snippet):
public static void answer400opt1q1 (int total, int total2, int total3)
{
Scanner word = new Scanner(System.in);
Scanner num = new Scanner(System.in);
System.out.print("ANSWER:");
String answer = word.nextLine();
System.out.print("player, enter your buzzing number: ");
int playerNumber = num.nextInt();
if(playerNumber == 1)
{
if(answer.equalsIgnoreCase("emmett"))
{
total =+ 400;
System.out.println("");
System.out.println("correct!");
}
else if(!(answer.equalsIgnoreCase("emmett")))
{
total =- 400;
System.out.println("");
System.out.println("incorrect answer!");
}
}
In questions400opt1() method, total, total2, and total3 are not declared variables. Declare them first before using.
This question already has answers here:
What does a "Cannot find symbol" or "Cannot resolve symbol" error mean?
(18 answers)
Closed 6 years ago.
I am a beginner in java and trying to create a program that recieves input numbers in terminal, and will continuously ask for a new numbers until 0 is entered. After 0 has been entered I want the program to summarize all of the numbers and plus them together. But when I try to compile the program I get this error:
Heres the code:
import java.util.Scanner;
public class SumTall {
public static void main(String[] args) {
Scanner tallscanner = new Scanner(System.in);
int tall = 0;
int tall1;
System.out.println("Write a number:");
tall1 = Integer.parseInt(tallscanner.nextLine());
while(tall1 > 0) {
System.out.println("Write another number:");
tall1 = Integer.parseInt(tallscanner.nextLine());
int tall2 = tall + tall1;
}
if(tall1 == 0) {
System.out.println(tall2);
}
}
}
You declared tall2 in while block declare it outside while. it will stick to that block only in your case it belong to while block but you are trying to access that variavle tall2 out side while that's the reason you can see that error. hope it will help you.
I changed the declaration part out side.
import java.util.Scanner;
public class SumTall {
public static void main(String[] args) {
Scanner tallscanner = new Scanner(System.in);
int tall = 0;
int tall1,tall2;
System.out.println("Write a number:");
tall1 = Integer.parseInt(tallscanner.nextLine());
while(tall1 > 0) {
System.out.println("Write another number:");
tall1 = Integer.parseInt(tallscanner.nextLine());
tall2 = tall + tall1;
}
if(tall1 == 0) {
System.out.println(tall2);
}
}
}
This question already has answers here:
How can I read input from the console using the Scanner class in Java?
(17 answers)
Closed 7 years ago.
I have been trying to find a way to make my code which does exponents accept an input for E and X. I know that if I use the scanner util, it would make this possible. But so far, I haven't found a way to do that. If you could help that would be sweet, thanks!
import java.util.Scanner;
public class SimpleExponents {
public static void main(String[] args) {
int e = 6;
int x = 4;
double result;
result = Math.pow(e,x);
System.out.println( result );
}
}
Scanner scanner = new Scanner(System.in);
int e = Integer.parseInt(scanner.next());
int x = Integer.parseInt(scanner.next());
or
Scanner scanner = new Scanner(System.in);
int e = scanner.nextInt();
int x = scanner.nextInt();