Return Char To Main

Oct 14, 2014

public static void main(String[] args) {
Scanner kb = new Scanner(System.in);
int hours = getHours(kb);
char major = getMajor(kb);

[code]....

I'm trying to return a char c,o, or x if that is their "major code" that the scanner grabbed.

View Replies


ADVERTISEMENT

Return Given Char That Matches Input String

Apr 17, 2015

Processing a string. How would I only return a given char that matches the input string e.g. v and/or n and/or m.

Everything else that does not match will return a '*' - e.g. user input = t result = *

I assume I need to also iterate through this input string using charAt() ?

View Replies View Related

User Input 20 Char And Program Will Print Most Common - Exception In Thread Main

Dec 17, 2014

My program is user input 20 char and the program will print the most common. So I use another int arr which count the number appears in the original array. i know its not so Effective but I don't know why it run but it stop in the middle. I got this code :

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 20
at Ex2.common(Ex2.java:39)
at Ex2.main(Ex2.java:23)

import java.util.Scanner;
class Ex2 {
public static void main(String[] arg) {
Scanner reader = new Scanner (System.in);
char[] arr=new char[20];
System.out.println("Please enter 20 chars:");
for (int i=0;i<20;i++)

[Code] ....

View Replies View Related

Keep Getting Zero Dollar Return When Run Main?

Feb 24, 2014

I keep getting a zero dollar return when I run my main. I am multiplying grossPay by hours but something is not catching.

public class employee {
private String name; //employees name
private int id; //employees id number

[Code].....

View Replies View Related

Return Value From Array To Main

Mar 11, 2014

I want to return values from arrays to the main and the problem is i cant use my variables from my constructor, I use new variables in my functions and i know this is no good, when I used the variables from the constructor in my function. I have a compilations errors,also i want to create un object in main and with this object i want to call the functions.

Java Code:

package javaapplication4;
import java.util.Scanner;
public class JavaApplication4 {
public static int[] MyInt;
public static double[] MyDouble;
public static String[] MyString;
public static char[] MyChar;

[Code] .....

The code is working when i run it and i have the right result in my screen but i know this is all wrong with the variables.

View Replies View Related

Return Int X To Main Method And Print It Out

Oct 10, 2014

I tried to create a simple program. The main method is supposed to call out the secondary method to use Scanner in order to ask a person to type in a number, which will be assigned to int x. Then the secondary method supposed to return the int x to main method, which supposed to print it out. And for some reason I just can't do it. No matter what the main method refusing to accept the int x.

import java.util.Scanner;
public class Return{
static Scanner newNum= new Scanner(System.in);
public static void main(String[] args){
getInt();
System.out.println(x);
}
public static getInt( ) {
// TODO Auto-generated method stub
int x;
System.out.print("give a num");
x= newNum.nextInt();
return x;
}}

View Replies View Related

Return Array Data From A Method Back To Main

Mar 16, 2014

I'm trying to return an array back to main. The array returned to main should contain the reversed random numbers array. I believe I have the array correctly reversed within the 'reverseArray' method. I'm trying to send this array back to main, but it appears to contain empty data (a bunch of zeros).

Java Code:

class ArrToMain {
public static void main(String[] args) {
final int NUMBER_OF_ELEMENTS = 1000;
double[] numbers = new double [NUMBER_OF_ELEMENTS];
//Invoke initialize method
initialize(numbers);

[Code] ......

View Replies View Related

Swing/AWT/SWT :: How To Return Values From A JForm To The Main Window On Close

Jan 26, 2014

I am making a java swing program. I have a main window that opens a JForm window when the user clicks a menu option. Then I have a button on the JForm that closes the window on click. However, I would also somehow like to make the JForm return values to the main window (according to the states of the selector components) when it is closed. How would I go about this? Currently my jForm is a seperate class called "NewGame", and inside the menu item mouse clicked method, I have the following code:

//open new game jform window
NewGame newGameWindow = new NewGame();
newGameWindow.setVisible(true);
newGameWindow.setLocationRelativeTo(null); //center window

Is there something I can add here to get the object's values upon the window's close? Or is there a way I can add that into the button clicked method on the actual jForm?

View Replies View Related

How To Return Array From A Method / Back Into Main Method That Prints Out Stuff

May 27, 2014

I'd like to know how to return a new array, I wrote in a method below the main method. I want to print the array but system.out.print doesn't work for arrays apparently. What structure i should use?

View Replies View Related

Method Must Return Int Type - If Given Integer Is Strong Return A / If Not Return B

Sep 7, 2014

I want to use a method, which takes for example an int and also returns an integer. For example, if the the given integer is strong return a, if it is notstrong return b. How would you write that in a Code?

I want to use that in a more general way. I want to give a method mlong the value X of the type date and let it return an int. Type date consists of 3 int, one of them is the int month.

mlong should return an int depending on the X.moth. at the moment my code looks like this:

// File1:
public class date {
public int day;
public int month;
public int year;
}

// File 2:
public class monthlength {
public int mlong(date X) {
int t;
t = X.month;
if (t == 1 || t == 3 || t == 5 || t == 7 || t == 8 || t == 10 || t == 12)
{ return 31; }
if(t == 4 || t == 6 || t == 9 || t == 11)
{return 30;}
}
}

View Replies View Related

How To Return Values In Object Return Type Function (method)

Apr 2, 2014

How do i take input values for TwoDPoint (which are objects) and return it back in numerical values also print them.

When i create an object in main method and pass values to my function of return type TwoDPoint,it gives error:- found int,int need TwoDPoiint,TwoDPoint.

// Here is what i tried to do:

Created class TwoDPoint that contains two fields x, y which are of type int. Defined another class TestTwoDPoint, where a main method is defined.In the main method created two TwoDPoint objects.

Then I modified the class TestTwoDPoint and add another function to it. This function takes two TwoDPoints as input and returns the TwoDPoint that is farthest from the point (0,0).

Then I added another function to TestTwoDPoint. This function takes two TwoDPoints as input and returns a new TwoDPoint whose x value is the sum of x values of the input TwoDPoint's and whose y value is the sum of the y values of the input TwoDPoint's.

class TwoDPoint {
int x = 2;
int y = 4;
}
class TestTwoDPoint {
public static void main(String args[]) {
TwoDPoint obj1 = new TwoDPoint();
System.out.println(obj1.x);
System.out.println(obj1.y);

[Code] ....

View Replies View Related

If Given Integer Is Even Return 1 / If Not Even Return 0

Sep 7, 2014

I want to use a method, which takes for example an int and also returns an integer. For example, if the the given integer is even return 1, if it is not even return 0. How would you write that in a Code?

I want to use that in a more general way. I want to give a method mlong the value X of the type date and let it return an int. Type date consists of 3 int, one of them is the int month.

mlong should return an int depending on the X.moth.

At the moment my code looks like this:

// File1:

public class date {
public int day;
public int month;
public int year;
}

// File 2:

public class monthlength {
public int mlong(date X) {
int t;
t = X.month;
if (t == 1 || t == 3 || t == 5 || t == 7 || t == 8 || t == 10 || t == 12)
{ return 31; }
if(t == 4 || t == 6 || t == 9 || t == 11)
{return 30;}
}
}

View Replies View Related

Int From Char Mapping

Apr 5, 2014

When casting a char which is read from a file to an int, can i assume that the mapping used will be ASCII? I've learned that unicode uses ASCII mappings for the characters that overlap.

Are there any other possibilities for int values of one character? I still have trouble understanding character encodings.

View Replies View Related

Limiting A Char

Oct 20, 2014

I was asigned to make a code that would limit the input to 1 character when asked for the initial of your middle name. So far I have the code ask for your first name then your last name and out put "Hello" firstname+last name. Im trying to add an 1 character middle itnitial in there.

View Replies View Related

Converting Int To A Char

Mar 3, 2015

I was reading about the char data type in Java. I know that an unsigned 16 bit integer is used to represent a char. So we can write the assignments below:

char a = 65; // a will get the value 'A'

But the limit of the char value is 65535.

So I've tried out a few things with char and trying to understand them but I'm not sure how they work.

char a =(char) 70000;
char b = (char) -1;

In the first case I thought that 70000 % 65535 would happen internally and the unicode character present at that location would get stored in 'a' but if I do that I get the answer of 70000 % 65535 as 4465. But when I display 'a' it shows me the output as '?'. Clearly '?' isn't at 4465.

In the second case I have no clue what's happening but somehow when I display 'b' it shows me '?' again.

View Replies View Related

Char To String

Oct 14, 2014

I need making char[] to a string im not entirely sure what to change i'm just suppose to use a string value but the upperclassmen used char:

char[] number = clear.toLowerCase().toCharArray();
for(int c = 0; c < number.length; c++) {
if(digit[c] < 'a' || digit[c] > 'z')
continue;

[code]...

View Replies View Related

How To Put All Char In Loop To String

Mar 16, 2014

I can't figure out how to have all of the random characters generated to go into the String. Below I can only get the last character to covert over to a String.

System.out.println("Original random character string:");
String printingString = "a";
for (int i = 0; i < 50; i++)//loop to obtain 50 random characters
{
char randomChar = (char) ((Math.random() * 255) +32);
System.out.print(randomChar);
printingString = Character.toString(randomChar); }
return printingString; }

View Replies View Related

Converting Char To Uppercase?

Jan 21, 2015

I'm trying to write something to will convert my Scanner input which will be either a string or a char toUpperCase but it is not working.
 
import java.io.File;
import java.util.Scanner; 
public class UpperCase {
 public static void main(String [] args) { 
Scanner kb = new Scanner(System.in);
char reply;

[code]....

View Replies View Related

Char Array Goes Out Of Bounds

Jan 16, 2014

Goal this time is to take a charArray, copy it into another charArray while reversing the things in it.

E.g. charArray["!ollaH"] into charArrayNew["Hallo!"]

My first idea was to revert the stuff in the Array with a ! cause i saw earlier that u can work with that too revert booleans. Sadly i didnt happen to make it work.

Next thing i thought of was a for loop to go trough the charArray and copy every section into charArrayNew just at the opposite end.

Java Code:

import java.util.Arrays;
public class aufgabe43 {
public static void main(String[] asgr){
char[] charArray

[Code] .....

Eclipse doesn't show any errors, and as u told me last time i did include import java.util.Arrays; to output the array in the end.

When i try to compile the code eclipse returns with an error

Java Code:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 68
at aufgabe43.main(aufgabe43.java:8) mh_sh_highlight_all('java');

Which I frankly don't understand since the array . Length is exactly the same.

View Replies View Related

Get User Input For A Char Value?

Jan 9, 2015

I am trying to get user input for a char value and am having some difficulty getting input for a char value.

Java Code:

//imports packages
import java.io.*;
import java.text.DecimalFormat;
class ModuleCulminatingTask {
public static void main (String args []) {
//declares variables
float var3, var4;
long var5 = (int)(Math.random()*10);

[code]....

View Replies View Related

How To Check Char Sequence

Jun 12, 2014

I what to check if value is not equal to CharSequence value

I try this but getting error:

Java Code:

private CharSequence testvalue = "";
if (!isEqualTo("BCDEF".contains(testvalue))){
}
public boolean isEqualTo(String s_src, String s_compareTo) {
boolean flag = false;

[Code] .....

View Replies View Related

Conversion Char To Double Value

Mar 31, 2015

I need to understand the java Conversion.

I have a char[] containing ASCII characters that need to be converted into int value and double value.

The int value are always stored in 1 char size like 'j'. I extracted it succesffully by converting the char in a ascii bytearray and then used: Integer.parseInt(sb.toString().replace("0x", ""), 16);

How can I get the Value as double when i used the char[] with size 2 or 4 ?

Example : final char[] charValue = { 'u', ' ', '}','+' }; what is the associate Double value ?

Example : final char[] charValue = { 'T', ' ' }; what is the associate Double value ?

Example : final char[] charValue = { 'T', ' ' }; what is the associate int value ?

View Replies View Related

Escape Backslash For Char

Mar 1, 2014

You can also use an escape code if you want to represent a character that can't be typed in as a literal, including the characters for linefeed, newline, horizontal tab,backspace, and single quotes.

char d = '
'; // A newline

char c = '"'; // A double quote

But for the newline code that is escaped above, it still gives me a new line. Is this a typo? Shouldn't it be '' for it to be escaped?

View Replies View Related

Getting Char At A Location In String

Oct 21, 2014

I found a fun program online and something so simple is giving me an issue. I c++ it is pretty simple fix, I can just call the strings location like an array. In java this is not the case. So far i have tried:

myString.charAt();
myString.indexOf();

There are a few other I found on google but I forget at the moment. I am just trying to close the gap on a string. It was a full sentence and I used replaceAll a few times to get several words I didn't want in the file out.

View Replies View Related

Amending Whole Words To Char

Apr 15, 2014

So my goal is to build a word search here. The road block I have run into is how to save words, input from user, into an array. Then once I figure that out I need to try and arrange them in such a way so that they will fit into my array without screwing with one another. It does not have to be working exceedingly well I mean really it can be assumed that the users will not try to screw the program up. Ie one or two words and a fairly large table will be all the input. Here is the program as of now:

import java.util.Random;
import java.util.Scanner;
public class BuildWS
{
int r;
int c;
char[][] array;
String query = " ";
 
[code]....

View Replies View Related

Least Significant Bit / Char Array

Oct 29, 2014

So I am working on a project for my Java course and for whatever reason, I am absolutely struggling with this assignment. I've made some progress but I can't seem to completely wrap my head around the algorithm I'm being told to use. I feel that everything is correct up to a particular point.I believe I am having issues moving a char array into a char matrix.

package edu.cofc.csci221.ui;
import java.lang.*;
public class Decoder
{
private int[][] M;

[code]...

Would I just need to loop through lsb one at a time and assign them to sequential spots within D? Basically call my get binary value and such in the outer loop and then use the inner to loop through both arrays and reassign values?

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved