I am storing out of range values in int and byte type
public class OverflowDemo { public static void main(String args[]) { int value = 2147483647 + 10; System.out.println(value); byte b=127+10; System.out.println(b); } }
Program will give error for only byte type as OverflowDemo.java:8: error: possible loss of precision
I have a assignment to do some Lexigraphic ordering. I have figured how to get the majority of this done, however, when I input my string values. No output takes place? :s
import java.util.Scanner; public class Lab03c { public static void main(String[] args) { // TODO Auto-generated method stub Scanner lexi = new Scanner (System.in); String s1,s2;
public void addEvent(ActionEvent evt) { uname = Util.getUname(); boolean a = EventDAO.add(this); if ( a) { message = "Event has been added!";
[Code] ....
While executing this..i get the following error: ORA-01861: literal does not match format string. Could it be due to any mismatch in date format (chrome browser automatically takes date in the format mm-dd-yyyy )? If yes, how do I resolve it? (I'm using Oracle database)
I have a table which contains list of regular expression and its corresponding value.I have to fetch those value and put it HASHMAP where regex as key.I have to compare the each key with the given string(input) and If matches I have to get the corresponding Value for the regex.
Now the problem here is it replaces all the occurrence of abc in the string value and I get the below output as :
value=""/xyz_12_1/xyz234/xyz/filename.txt";
However my requirement is only in the case the value exactly matches with source the replacement shd happen. I am expecting the output like this :
String value ="/abc_12_1/abc234/xyz/filename.txt";
Also the above code is in a function which will be called multiple times and the values will keep on changing. However the target and source will remain the same always.
The program should output all numbers between the starting and ending number that are a multiple of the number N. Your solution must use a for-loop. Here is example output from running the program:
import java.util.Scanner; public class MultiplyNThree { @SuppressWarnings("resource") public static void main(String[] args) { Scanner userInputScanner = new Scanner(System.in); System.out.println("Enter 1st number: "); int start = userInputScanner.nextInt();
import java.util.Scanner; public class Practice { public static void main(String[] args) { //get user input Scanner user_input = new Scanner(System.in); System.out.print("Enter a number: " );
public class op{ String word = "Hello"; //my variable public void reverseword() //My function { for(int i =word.length();i>=0 ;i--) { System.out.println(word.charAt(i));
[code]....
when i call function in main i have this error:
run: Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 5 at java.lang.String.charAt(String.java:658) at javacourse.Car.opname(Car.java:35) at javacourse.JavaCourse.main(JavaCourse.java:24) Java Result: 1
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String ind ex out of range: 10 at java.lang.String.charAt(String.java:658) at StringChar.main(StringChar.java:11)
Code :
class StringChar{ public static void main(String ss[]){ String str="HelloWorld"; int a; System.out.println("String is = " + str); a=str.length(); System.out.println("String is After Reverse"); for(int i=a;i>=0;i--) System.out.print(str.charAt(i)); } }
I have a large text file of 1 GB size. I need to print the line when a matching word is found in a particular line. Below is the code I am using. But if there are many lines that has the matching word, it's taking lot of time. Any solution to print the lines much faster.
Scanner scanner = new Scanner(file); while (scanner.hasNextLine()) { String line = scanner.nextLine(); if(line.contains("xyz")) { System.out.println(line); } }
Alright so I wrote a switch statement that decides what range to print based on the letter grade input.
import java.util.Scanner; public class SwitchPractice { public static void main(String [] args) { Scanner scan = new Scanner(System.in);
[code]...
It works fine, but once it the user enters a letter grade and then displays the value, it does not prompt the user for another letter grade so that it can perform the output again. Also if I wanted to display an error message to the user if they enter an invalid letter grade how would I do that. I tried using a while loop and if statement in the switch statement but that didn't work.
I am trying to write a program which asks the user to enter two numbers and then do the arithmetic operation based on user's input . No compiling errors but when I run the program I keep getting "StringIndexOutOfBounds" error .
class arithmetic { public static void main(String[] args){ Scanner in = new Scanner(System.in); int ent1 = 0;
My Computer Programming teacher has given the class a problem that requires the use of var.charAt(), var.length() and while/for. Basically, the problem is that we have to create program that'll show a mirrored or reverse version of the entered word. Like for example, if your input is the word "Hello" (the quotation marks aren't included), the output will be "olleH".
Here's the code:
import java.io.*; public class StringMirror {public static void main (String [] args) throws IOException {BufferedReader scan = new BufferedReader (new InputStreamReader(System.in)); String enteredWord = ""; int lengthOfTheWord = 0; int lengthOfTheWordMinusOneVersion = 0;
[code]....
It is working, but the problem is that after the output, there's this error that says String index out of range: -1.
the program is working but I kind of wanted it to have no errors in the end.
I'm trying to put together a method that formats telelphone numbers, but there's a part of my code that not working. If I enter (305)912-5458 into the variable phoneNumb I get an index is out of range error. I added a lot of system out messages so that I can try to get an idea of why the code was crashing.
public static void main(String[] args) { int intBegin = 0; int intEnd = 1; int length; String charact; StringBuilder numbuilder = new StringBuilder();
[Code] .....
The error message I'm getting is:
run: The length is 13 intBegin is at 0 intEnd is at 1 index is at 0 Charcter ( was not inserted
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.Find the sum of all the multiples of 3 or 5 below 1000.
public class ClassEcerciseOne { public static void main(String[] args) { // TODO Auto-generated method stub int x=0; int y=0; for (x=0;x < MAX_VALUE;x++){ if (x/3==0){ System.out.println(x); int z= x++;
i have a problem, im trying to get some values from a jtable (tabla) and insert them in a mysql database, so i scan the table for some values to know which of the rows i must insert ("s" or "n").
I'm able to insert few rows, but when the last row with "s" or "n" is inserted it launch me a NullPointerException and I dont know why.