How To Find Whether A Number Is Palindrome Or Not
Aug 6, 2014Any simplest code to check whether a number is palindrome or not?
View RepliesAny simplest code to check whether a number is palindrome or not?
View RepliesI want to find the prime palindrome numbers less that a given number by my program. Here is my code, I am trying to find the method to solve the errors when I compile it. It said variable a might not have been initialized in line 41,62,86.
import java.util.Scanner;
public class Lab5{
public static void main (String[] args){
System.out.println("Please input a number");
Scanner Input=new Scanner(System.in);
int num = Input.nextInt();
[Code]...
I'm in the process of writing a program that determines if a number is a Palindrome or not. I'm not allowed to use strings and am required to use the getSize method shown below. I believe my issue that I'm having is that the "num" is not being called in the getSize method, and therefore not running the while loop, or at least that is what I believe is the issue.
import javax.swing.*;
public class getSize{
public static void main( String[] args )
{
int num;
num = Integer.parseInt (JOptionPane.showInputDialog ( "Please input a number" ));
[code]....
I have to write a program that inputs a 5 digit integer from the keyboard and prints if the input number is a palindrome or not. I got it to work, but when my result prints it says "0 is a palindrome" or "0 is not a palindrome". How can I get rid of the 0 and replace it with the number input by the user?
import java.util.Scanner;
public class Palindrome {
public static void main(String[] args) {
int number;
int digit;
int temp;
[code]....
I have to find the average, highest, and lowest numbers in an array. I already have the average and highest, and I thought I could find the lowest number the same way I found the highest, but it's not working. It just keeps coming out to 0. I've tried out different ways, but I want to see if there are better ways than doing MAX_VALUE for the lowest, then looping it through.
import java.util.Scanner;
public class Test_Scores {
public static void main(String[] args) {
//array,scanner,values
[Code].....
Write a program to find the number of and sum of all integers greater than 100 and less than 200 that are divisible by 7.
View Replies View Relatedfiguring out the logic to print the day number of the year. The directions for my homework are: Write a program that prints the day number of the year, given the date is in the form: month day year. For example, if the input is 1 1 05, the day number is 1; if the input is 12 25 05, the day number is 359. The program should check for a leap year . I have a basic outline of the program but i am having trouble with figuring out the logic to display the day number of the year given the date. This is what i have so far
import javax.swing.JOptionPane;
public class Practice4 {
public static void main(String[] args){
String monthStr;
String dayStr;
int inputMonth;
[code]....
what I needed to know to complete the lesson, but now it just tells me what the output should be and I have to research the information on my own. anyways, here is my code from the previous lesson:
import java.util.Random;
import java.util.Scanner;
public class tnArray {
public static void main(String[] args) {
int [] array;
[code]....
Now I have to change it so that instead of counting the number of times a number will appear in the array, I must output which slot in the array the number is in.
I am working through a text and I am supposed to complete the following tasks.
Your ReadFiles.java class requires the following methods:
Method: check to see if the file exists
Method: find number of rows in csv file
Method: Converts the csv file to a mutli-dimensional array
Method: PrintArray
Method: Return array using a get method
Create a file DataAnalyzer.java. This file will be used to call the methods in ReadFiles.java. Be sure to demonstrate that all of your methods work through DataAnalyzer.java.
The problem is that it does not really provide any information on how to go about reading a file into an array. I am stuck at the third task of converting the file to an array and I have tried several ways to do this unsuccessfully. I thought that I would at least try to get things to print out (line 87) to see if I could get that to work, but all that prints in null over and over again.
Java Code:
public class DataAnalyzer {
public static void main (String[] args) {
ReadFiles aReadFiles = new ReadFiles();
aReadFiles.fileCheck();
aReadFiles.findRows();
aReadFiles.convertFile();
[Code] .....
I have 2 arrays in random order of 10 numbers.I need to find the biggest number from array A and B and then when its on a screen second thing is to multiply those numbers by 2.
import java.util.Random;
public class Projektas {
public static void main(String arng[]){
int i,j;
int A[] = new int [10];
int B[] = new int [10];;
[code]..
I am doing this math for my assignment where you have to find the imaginary number.
double dem = (b*b-4*a*c)*-1;
double dem2 = Math.sqrt(dem);
realPart = (-b/(2*a));
imagine = (dem2)/(2*a);
imagineneg = (dem2)/(2*a);
So basically I am trying to get it that the number inside the square root isnt negative. So lets say I enter a: 1, b: -1, c: 4.25. When you do the discriminant it would be -16 but I want that to be positive so I multiple it by -1 (thats the dem part). Then I sqaure root the whatever the answer is and then go to the imagine and imagineneg part where you find the imaginary number.
My problem is that instead of it being -16*-1 to get 16, some how I get 15.
I need to find if the number entered by the user are consecutive or not!
Ex:this should return a true!! This should return false!
(1,2,3) (3,5,7)
(3,2,4) (1,2,2)
(-10,-8,-9) (7,7,9)
My program seems to work ok when i enter number in order like 1,2,3 = true , and all the numbers for false seem to be working as well! my problem is when i enter number like 3,2,4 that are not in order but still are consecutive!! I thought that another if statement would be the solution but i have tray several different ones and still can't make it work !!!
Java Code:
import java.util.*;
public class Consecutive{
public static void main (String [] args){
Scanner console= new Scanner(System.in);
System.out.println("Enter three numbers");
String numbers = console.nextLine();
[[Code] .....
This is my code up to now and I can't do anything to make it work. I want it to tell me how many times the number 3 appears, and the last position it was in. I am getting errors like"Cuanto.java:88: getPosition(double[],double) in Cuanto cannot be applied to (double) ....
a = getPosition(a);" and unreachable statements, and value not found. It's all over the place every time I make a change to it.
Java Code:
public class Cuanto {
static int getPosition(int count,double listOfValues[],
double targetValue) {
int a = 0, i;
for (i=0; i < listOfValues.length; i++) {
if (listOfValues[i] == targetValue) {
a++;
[Code] ....
I am having a problem with SD array .i have to find the ASCII no. of names entered.
import java .io.*;
class ASCII
{
public static void main()throws IOException
{
InputStreamReader read = new InputStreamReader(System.in);
[Code] .....
I wrote this simple piece of code to find the number in the given array of Integers. The program works fine although it shows a couple of errors when i modify it a little bit.
public class DemoLabel{
public static void main(String [] args){
int[][] arrofInts={
{32,45,67,87},
{23,44,55,66},
{12,47,87,56},
{23,44,12,78}
[Code] .....
In the disp() method,Suppose i only want to pass two arguments i.e disp(i,j) given that searchFor variable is visible in the entire class but when i use disp(i,j) i get the following error
DemoLabel.java:38: error: cannot find symbol System.out.println("The number "+searchFor+" is at the location"+i+" , "+j);
^
symbol: variable searchFor
location: class DemoLabel
So i decided to declare the
int searchFor
as
public int searchFor
But the compiler threw another error saying that it was a Illegal start of expression
Also,when i add a SOP line after the label search: it shows the error
DemoLabel.java:25: error: undefined label: search
continue search;
^
Although i got the program to work it would be useful if i could understand why it doesn't work with the modifications.
Write a program to find the number of and sum of all integers greater than 100 and less than 200 that are divisible by 7.
View Replies View RelatedThe program should find the biggest corner, based on the number zero.
A zero becomes a corner when there's the same amount of zeros under it, and left to it.
The program should print a message saying what's the biggest corner size.
Corner size is the number of zeros inside it.
Java Code:
import java.util.*;
class Corners
{
static Scanner reader=new Scanner(System.in);
static final int N=25;
static int corners(int a, int b, int[][] m)
[Code] ....
That's the output:
Java Code:
The BOX:
1 0 0 1 1 1 0 1 0 1 0 0 1 0 0 0 1 0 0 0 0 0 1 1 1
1 0 1 0 1 0 0 1 0 0 0 1 0 1 1 1 0 1 0 0 0 1 1 1 0
0 1 1 1 1 1 0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 1 0 0 0
0 1 0 1 0 1 1 1 1 1 1 0 0 0 1 1 0 0 1 1 0 1 0 0 1
0 0 1 1 0 0 0 0 0 1 0 0 0 0 1 0 0 1 0 0 0 0 1 1 0
[Code] ....
code a 10 * 10 matrix, with random numbers from 1 to 100,
i) Find the most repeated number.
ii) Use the Binary Sort, to sort the matrix in ascending order.
iii) Find the Column, with the highest average number.
Is there any way to find how many number of elements are landing in same bucket in HashSet. I know Reflection could be one way but i am not able to design a program for that.
View Replies View Relatedimport java.util.Scanner;
public class AvgLrgSml{
public static void main(String[]args){
System.out.print("Hello there. Please enter any three numbers.");
Scanner keyboard = new Scanner(System.in);
double num1 = keyboard.nextDouble();
double num2 = keyboard.nextDouble();
[Code]...
Java program takes positive int from user and determine if prime. Next the program finds next highest or next lowest prime number.
import java.io.*;
import java.util.*;
public class pa2take2 {
public static void main (String[]args){
int menus; //menu selection
[Code] ......
I am writing a payroll program .The program generates random PPS numbers and then takes in users information and calculates the salary accordingly. I am using netbeans and my code is showing errors on line 18 and 42 ("cannot find symbol")on the code for grossPay(). The program seems to crash after a new PPS number is generated and will not run.
package sd_assg_2;
import java.util.Arrays;
import java.util.Random;
import javax.swing.JOptionPane;
public class SD_ASSG_2 {
public static void main(String[] args) {
String[] newPPs = getPPSno();
[Code] ....
I want to ask how to make Palindrome in Java with 2 methods //Output is Like this
Input a word
Hey
Not a Palindrome
Reverse
yeH
I have the following code to check for five characters palindrome but it always give me incorrect answer that if i have a word like radar the answer it isn't a palindrome. and if i changed any thing in the code i got either stack overflow or index out of bounds exception
The code is as the following
import java.util.Scanner;
public class Palindrome {
int first =0;
static int n;
int last = 4;
int y = 0;
public static void main(String [] args)
[Code] .....
I recently have tryed to make a java code that reads words and say if its palindrome or not. I want to fix two things but unfortunately i can't do it on my own.
1st thing that i want fix is that when i run the code i have to press 2x times enter..and i dont know why?(i want one time to press it when i write the text)
2nd thing that i want to fix is that when you run it you can put as many words as you can..only when you write "END" the code must ends.
So unfortunately my code runs only for 1 time.(one word)
My code:
class test {
public static void main(String args[]) {
System.out.print( "#Enter text : " );
String text = BIO.getString();
String reverse = BIO.getString();
int length = text.length();
[Code] .....
I'm supposed to use stacks (implemented with an array) to check to see if a string is a palindrome. I've finished all my classes and methods, but I'm getting an ArrayIndexOutOfBoundsException when I try to run my demo program.Here are my classes:
public interface Stack {
// Creates an empty stack
public void initializeStack()
// Returns true if the stack is empty, returns false otherwise
public boolean isEmpty();
// The stack can never be full, so always return false
public boolean isFullStack();
[code]...